package com.yf1706.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yf1706.bean.GapFilling;
import com.yf1706.bean.Judge;
import com.yf1706.bean.QuestionBank;
import com.yf1706.dao.jpa.judgeJDAO;
import com.yf1706.dao.jpa.questionBankJDAO;
import com.yf1706.dao.mybatis.JudgeMDAO;

@Service
public class judgeService {
	@Autowired
	private judgeJDAO jjdao;
	@Autowired
	private JudgeMDAO jmdao;
	@Autowired
	private questionBankJDAO qbjdao;
	
	public List<Judge> findByQuestionBank(QuestionBank q){
		return jjdao.findByQuestionBank(q);
	}
	
	public List<Judge> querybyQbId(int qbId){
		return jmdao.querybyQbId(qbId);
	}
	
	//在题库添加题目
	public void questionbankAddJudge(String answer,String examQuestion,String qbId,String createPeople){
		Judge sc=new Judge();
		sc.setAnswer(answer);
		sc.setCreateDate(new Date());
		sc.setExamQuestion(examQuestion);
		sc.setCreatePeople(createPeople);
		int qbid=Integer.parseInt(qbId);
		sc.setQuestionBank(qbjdao.findByQbId(qbid));
		jjdao.save(sc);
	}

	public void deleteQuestionBankJudge(int judgeId) {
		jjdao.deleteById(judgeId);
		
	}

	public List<Judge> queryAllJudge() {
		return jmdao.queryAllJudge();
	}

	public List<Judge> queryAllByQbIdAndExamQuestion(int qbId, String examQuestion) {
		
		return jmdao.queryAllByQbIdAndExamQuestion(qbId,examQuestion);
	}

	public List<Judge> findByJudgeId(int judgeId) {
		// TODO Auto-generated method stub
		return jjdao.findByJudgeId(judgeId);
	}

	public void deletJudgeById(int judgeId) {
		jjdao.deleteById(judgeId);
		
	}

	public void add(String examQuestion, String answer, int qbId, String sessionUserName) {
		Judge j=new Judge();
		j.setAnswer(answer);
		j.setCreateDate(new Date());
		j.setCreatePeople(sessionUserName);
		j.setExamQuestion(examQuestion);
		j.setQuestionBank(qbjdao.findByQbId(qbId));
		jjdao.save(j);
	}
}
